﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
using RestService1.POCO;

namespace RestService1
{
    // NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "RestServiceImpl" in code, svc and config file together.
    public class RestServiceImpl : IRestServiceImpl
    {
        public string XMLData(string id)
        {
            return "XML: You requested product " + id;
        }

        public string JSONData(string id)
        {
            return "JSON: You requested product " + id;
        }

        public Person GetPerson(string id, string name)
        {
            return new Person { Id = id, Name = name };
        }

        public ResponseUser GetUser(string name)
        {
            RestServiceEntities _context = new RestServiceEntities();
            var result = from u in _context.Users
                         where u.UserName.Contains(name)
                         select new ResponseUser
                         {
                             Name = u.UserName,
                             Password = u.Password,
                             Description = u.Description
                         };
            return result.FirstOrDefault();
        }

        public IEnumerable<ResponseUser> GetListUser()
        {
            RestServiceEntities _context = new RestServiceEntities();
            var result = from u in _context.Users
                         select new ResponseUser
                         {
                             Name = u.UserName,
                             Password = u.Password,
                             Description = u.Description
                         };
            return result;
        }
    }
}
